<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>爱宠医院管理系统</title>
	<meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>    
	<link href="css/Common.css" rel="stylesheet" type="text/css" />
    <link href="css/sitegeneric08.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../js/public_fuc.js"></script>
    <style type="text/css">
    	.bt-input{
    		width: 50%;height: 34px;border-radius:5px;
    	}
    	.col-2{
    		width: 90px;
    		display: inline-block;
    	}
    </style>
  </head>
  
  <body>
<!-- head如果图片高度不合适。请修改Common.ces里面的".Header .HeaderTop"的高度。和".Header"的高度-->
<jsp:include flush="true" page="incTop.jsp"></jsp:include>    
<!-- head-->
	
	
	
	
<!--body-->
<div align="center" class="Wrapper">
<div id="MainCenter" align="center" class="MainCenter">
	     <div id="navigation" class="naivgation">
				<jsp:include flush="true" page="incLeft.jsp"></jsp:include>
		 </div>
		 <div id="content" class="Sub">
				<div class="NewContainer771">
					<div class="BoxHeader">
						<div class="BoxHeader-center MarginTop10">医生管理</div>
					</div>
					<div class="Slot"  style="height: 100%">
				        <span class="col-2">姓名</span>
						<input type='text' id='name' class="bt-input" placeholder="" />
					
				         <br/>
				         <br/>
				        <span class="col-2">性别</span>
						<input type='text' id='sex' class="bt-input" placeholder="" />
					
				         <br/>
				         <br/>
				        <span class="col-2">照片</span>
						<input type='text' id='photo' class="bt-input"/>
						
				         <br/>
				         <br/>
				        <span class="col-2">职称</span>
						<input type='text' id='username' class="bt-input" placeholder="" />
					
				         <br/>
				         <br/>
				        <span class="col-2">权限</span>
						<input type='text' id='password' class="bt-input" placeholder="" />
					
				         <br/>
				         <br/>
				        <span class="col-2">主治专业</span>
						<select id='roleId' class="bt-input"></select>
						
				         <br/>
				         <br/>
						<button id="add_staff">添加医生</button>
                    </div>
				</div>
		 </div>
</div>
</div>
<!--body-->
	
	
	
<!--foot -->	
<div align="center" class="Wrapper">
	<div style="height: 40px;" align="center" class="Footer">
		<ul style="margin-top: 13px;">
			<li>
				<a>网站声明</a>&nbsp;&nbsp; |&nbsp;&nbsp;
				<a>服务网点</a>&nbsp;&nbsp; |&nbsp;
				<a>网站地图</a>&nbsp; |&nbsp;&nbsp;
				<a>联系我们</a>&nbsp;&nbsp; |&nbsp;&nbsp;
				<a>客服热线：********</a> 
			</li>
		</ul>
	</div>
</div>
<!--foot -->	
<script type="text/javascript">
      $(function() {
        $("#leftnav").load("pubnav.html");
        addStaff();
		 //绑定input = file 监听
		$("#photo").change(function(){
 		    readURL(this,$("#photo_preview"));
 		});
		
		$.get("api/role/list",function(data){
			var html = '';
			if (data.code== 0) {
				var arr = data.data;
				for (var i = 0,len = arr.length; i < len; i++) {
					var obj = arr[i];
					html += '<option value="'+obj.id+'">'+obj.name+'</option>';
				}
			} else {
				html += '<option value="-1">请先添加权限</option>';
			}
			
			document.getElementById('roleId').innerHTML = html;
		});
		
		
      });
      
		//预览
     	function readURL(input,show) {
		if (input.files && input.files[0]) {
		    var reader = new FileReader();
	           reader.onload = function (e) {
		          show.attr('src', e.target.result);
		        }
		        reader.readAsDataURL(input.files[0]);
		 	}
		}
      
      
			 //增加staff
      var addStaff = function(){
      	$('#add_staff').click(function(){
			var roleIdValue = document.getElementById('roleId').value;
			if (roleIdValue == '-1') {
				alert("请先添加权限");
				return false;
			}
      		var formData = new FormData();
      		formData.append("name", document.getElementById('name').value);
      		formData.append("sex", document.getElementById('sex').value);
      		formData.append("files[0]", document.getElementById('photo').files[0]);
      		formData.append("username", document.getElementById('username').value);
      		formData.append("password", document.getElementById('password').value);
      		formData.append("roleId", document.getElementById('roleId').value);
			$.ajax({
              url: 'api/staff/save',
              type: 'POST',
              data: formData,
              cache: false,
              dataType:'json',
              contentType: false,
              processData: false,
              success: function (data) {
                  if(data.code=='0'){
                	 //window.location.href = 'staff.jsp';
                	 alert('添加工作人员成功');
                	 window.location.reload();
                  }
              }
             });
             return false;
    	  });
      }
      
      
    </script> 
</body>
</html>
